package com.example.apple.tianqiyubaoone;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.example.apple.tianqiyubaoone.DATA.Data;

/**
 * Created by apple on 17/3/7.
 */
public class FutureSixDayActivity extends Activity{
    Button 未来天气返回;
    ListView listView;
    BaseAdapter myAdapter;
    LinearLayout viewl;
    DrawingFunction drawingFunction;
    final Data data = Data.createSingletonData();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.futuresixday);
        未来天气返回 =(Button) findViewById(R.id.未来天气返回);
        listView =(ListView) findViewById(R.id.未来天气列表);
        viewl= (LinearLayout) findViewById(R.id.viewl);
        drawingFunction = new DrawingFunction(this,data.getResult().getFuture().getMaxTemperature(),data.getResult().getFuture().getMinTemperature());
        viewl.addView(drawingFunction);
        未来天气返回.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
    });
        bindingData();
        listView.setAdapter(myAdapter);
    }
    void bindingData(){
        myAdapter = new BaseAdapter() {
            @Override
            public int getCount() {
                return data.getResult().getFuture().getFutureSevenDays().size();
            }

            @Override
            public Object getItem(int position) {
                return null;
            }

            @Override
            public long getItemId(int position) {
                return 0;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                ViewHoder viewHoder;
                if (convertView==null){
                    convertView =View.inflate(FutureSixDayActivity.this,R.layout.futuresixday_item,null);
                    viewHoder = new ViewHoder();
                    viewHoder.temperature =(TextView) convertView.findViewById(R.id.temperature);
                    viewHoder.weather =(TextView) convertView.findViewById(R.id.weather);
                    viewHoder.wind = (TextView) convertView.findViewById(R.id.wind);
                    viewHoder.week = (TextView)convertView.findViewById(R.id.week);
                    viewHoder.date = (TextView)convertView.findViewById(R.id.date);
                    convertView.setTag(viewHoder);
                }else {
                    viewHoder =(ViewHoder) convertView.getTag();
                }
                //Log.e("--->数据添加",data.getResult().toString());
                viewHoder.temperature.setText(data.getResult().getFuture().getFutureSevenDays().get(position).getWeatherData().getTemperature().toString());
                viewHoder.week.setText(data.getResult().getFuture().getFutureSevenDays().get(position).getWeatherData().getWeek());
                viewHoder.wind.setText(data.getResult().getFuture().getFutureSevenDays().get(position).getWeatherData().getWind());
                viewHoder.weather.setText(data.getResult().getFuture().getFutureSevenDays().get(position).getWeatherData().getWeather());
                viewHoder.date.setText(data.getResult().getFuture().getFutureSevenDays().get(position).getDate());
                Log.e("七天的最小-->",data.getResult().getFuture().getMinTemperature().get(0));

                return convertView;
            }
        };

    }

    private class ViewHoder {
        TextView temperature,weather,wind,week,date;
    }
}
